#ifndef __CAPTURE_H__
#define __CAPTURE_H__

#include "common.h"

#include <opencv/cv.h>

#include "DeckLinkAPI.h"

class DeckLinkCapture : public IDeckLinkInputCallback
{
public:
    DeckLinkCapture(int width, int height);
    ~DeckLinkCapture();

	virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, LPVOID *ppv) { return E_NOINTERFACE; }
	virtual ULONG STDMETHODCALLTYPE AddRef(void);
	virtual ULONG STDMETHODCALLTYPE  Release(void);
	virtual HRESULT STDMETHODCALLTYPE VideoInputFormatChanged(BMDVideoInputFormatChangedEvents, IDeckLinkDisplayMode*, BMDDetectedVideoInputFormatFlags);
	virtual HRESULT STDMETHODCALLTYPE VideoInputFrameArrived(IDeckLinkVideoInputFrame*, IDeckLinkAudioInputPacket*);

    // Ilias
    static QString toQString(CFStringRef str);

    void        convertFrameToOpenCV(void* frameBytes, IplImage * m_RGB, int width, int height);
    IplImage*   captureLastFrame();

    int start();

private:
    ULONG				m_refCount;
	pthread_mutex_t		m_mutex;

    //Ilias
    IplImage*           lastImage;
     void* frameBytes;
    int m_Height, m_Width;
IDeckLinkIterator           *deckLinkIterator;

    void bail();
};

#endif
